package com.engine.zx.controller;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.zx.service.KqCloseAccountService;
import com.engine.zx.service.impl.KqCloseAccountServiceImpl;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

public class KqCloseAccountAction {

    private KqCloseAccountService getService(User user) {
        return  ServiceUtil.getService(KqCloseAccountServiceImpl.class, user);
    }


    @GET
    @Path("/closeAccount")
    @Produces(MediaType.TEXT_PLAIN)
    public String closeAccount(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> data = new HashMap<>(8);
        try {
            User user = HrmUserVarify.getUser(request, response);
            data.put("data",getService(user).closeAccount(ParamUtil.request2Map(request)));
            data.put("code", 200);
        } catch (Exception e) {
            data.put("code", 500);
            data.put("msg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(data, SerializerFeature.DisableCircularReferenceDetect);
    }


    @GET
    @Path("/getWorkflowList")
    @Produces(MediaType.TEXT_PLAIN)
    public String getWorkflowList(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> data = new HashMap<>(8);
        try {
            User user = HrmUserVarify.getUser(request, response);
            data.put("data",getService(user).getWorkflowList());
            data.put("code", 200);
        } catch (Exception e) {
            data.put("code", 500);
            data.put("msg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(data, SerializerFeature.DisableCircularReferenceDetect);
    }


    @GET
    @Path("/checkSubmit")
    @Produces(MediaType.TEXT_PLAIN)
    public String checkSubmit(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> data = new HashMap<>(8);
        try {
            User user = HrmUserVarify.getUser(request, response);
            data.put("data",getService(user).checkSubmit(ParamUtil.request2Map(request)));
            data.put("code", 200);
        } catch (Exception e) {
            data.put("code", 500);
            data.put("msg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(data, SerializerFeature.DisableCircularReferenceDetect);
    }
}
